<?php

class Admin_Models_Customer extends Libs_Model {

    private $cus_id;
    private $title;
    private $email;
    private $password;
    private $phone;
    private $address;
    private $gender;
    private $avatar;
    private $active;
    private $resetkey;
    private $post_date;
    private $first_name;
    private $last_name;
    private $dob;

    public function setActive($active) {
        $this->active = $active;
    }

    public function getActive() {
        return $this->active;
    }

    public function setResetkey($resetkey) {
        $this->resetkey = $resetkey;
    }

    public function getResetkey() {
        return $this->resetkey;
    }

    public function setDob($dob) {
        $this->dob = $dob;
    }

    public function getDob() {
        return $this->dob;
    }

    public function setAddress($address) {
        $this->address = $address;
    }

    public function getAddress() {
        return $this->address;
    }

    public function setCusId($cus_id) {
        $this->cus_id = $cus_id;
    }

    public function getCusId() {
        return $this->cus_id;
    }

    public function setAvatar($avatar) {
        $this->avatar = $avatar;
    }

    public function getAvatar() {
        return $this->avatar;
    }

    public function setEmail($email) {
        $this->email = $email;
    }

    public function getEmail() {
        return $this->email;
    }

    public function setFirstName($first_name) {
        $this->first_name = $first_name;
    }

    public function getFirstName() {
        return $this->first_name;
    }

    public function setGender($gender) {
        $this->gender = $gender;
    }

    public function getGender() {
        return $this->gender;
    }

    public function setLastName($last_name) {
        $this->last_name = $last_name;
    }

    public function getLastName() {
        return $this->last_name;
    }

    public function setPassword($password) {
        $this->password = $password;
    }

    public function getPassword() {
        return $this->password;
    }

    public function setPhone($phone) {
        $this->phone = $phone;
    }

    public function getPhone() {
        return $this->phone;
    }

    public function setPostDate($post_date) {
        $this->post_date = $post_date;
    }

    public function getPostDate() {
        return $this->post_date;
    }

    public function setTitle($title) {
        $this->title = $title;
    }

    public function getTitle() {
        return $this->title;
    }

    public function setValue($row, $isKey = true) {
        $cus = new Admin_Models_Customer();
        if ($isKey) {
            $cus->setCusId($row['cus_id']);
        }
        $cus->setPhone($row['phone']);
        $cus->setEmail($row['email']);
        $cus->setAddress($row['address']);
        $cus->setAvatar($row['avatar']);
        $cus->setActive($row['active']);
        $cus->setResetkey($row['resetkey']);
        $cus->setFirstName($row['first_name']);
        $cus->setLastName($row['last_name']);
        $cus->setPostDate($row['post_date']);
        $cus->setGender($row['gender']);
        $cus->setPassword($row['password']);
        $cus->setTitle($row['title']);
        $cus->setDob($row['dob']);
        return $cus;
    }

    public function getKeyAndValue(Admin_Models_Customer $cus, $isKey = false) {
        $data = array();
        if ($isKey) {
            $data['cus_id'] = $cus->getCusId();
        }
        $data['email'] = $cus->getEmail();
        $data['password'] = $cus->getPassword();
        $data['phone'] = $cus->getPhone();
        $data['address'] = $cus->getAddress();
        $data['first_name'] = $cus->getFirstName();
        $data['last_name'] = $cus->getLastName();
        $data['gender'] = $cus->getGender();
        $data['title'] = $cus->getTitle();
        $data['dob'] = $cus->getDob();
        $data['post_date'] = $cus->getPostDate();
        $data['avatar'] = $cus->getAvatar();
        $data['active'] = $cus->getActive();
        $data['resetkey'] = $cus->getResetkey();

        return $data;
    }

    public function __construct() {
        parent::__construct();
    }

    public function getAllCustomer() {
        $sql = "select * from tbl_customers order by post_date desc";
        $result = $this->db->fetchAllO($sql);
        while ($rows = mysql_fetch_assoc($result)) {
            $out[] = $this->setValue($rows);
        }
        return $out;
    }

    public function delCustomer($cus_id) {
        $sql = "delete from tbl_customers where cus_id = $cus_id";
        $this->db->query($sql);
    }

}
